package com.lego.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lego.bean.OrdersAndGoodsImgVO;
import com.lego.bean.PersonalReviewVO;
import com.lego.service.GoodsService;
import com.lego.service.OrdersService;
import com.lego.service.impl.GoodsServiceImpl;
import com.lego.service.impl.OrdersServiceImpl;

@WebServlet("/selcetUserReviews.do")
public class SelcetUserReviewsServlet extends HttpServlet {
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		OrdersService ods = new OrdersServiceImpl();
		int userId = 0;
		int pageNum = 0;
		int pageSize = 0;
		try {
			userId = Integer.parseInt(request.getParameter("userId"));
		} catch (Exception e) {
			System.out.println("没有用户登录！");
		}
		try {
			pageNum = Integer.parseInt(request.getParameter("pageNum"));
		} catch (Exception e) {
			pageNum = 1;
		}
		try {
			pageSize = Integer.parseInt(request.getParameter("pageSize"));
		} catch (Exception e) {
			pageSize = 2;
		}
		List<OrdersAndGoodsImgVO> list = ods.selectPersonalReview(userId,pageNum,pageSize);
		int totalRows = ods.seletPersonalRws(userId);
		PersonalReviewVO<OrdersAndGoodsImgVO> prvo = new PersonalReviewVO(list,pageNum,pageSize,totalRows);
		response.setContentType("application/json;charset=utf-8");
		ObjectMapper om = new ObjectMapper();
		String str = om.writeValueAsString(prvo);
		System.out.println(str);
		response.getWriter().write(str);
	}
}
